package com.sinodata.bsm.center.engine.notify;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class NotifyModeFactory {

    private static final Logger logger = Logger.getLogger(NotifyConfig.class);

    private static NotifyModeFactory instance = null;

    private final Map<String, NotifyMode> modeMap = new HashMap<String, NotifyMode>();

    /**
     * 
     */
    private NotifyModeFactory() {
        List<NotifyConfig> configs = NotifyConfig.getAlarmConfigs();
        for (int i = 0; i < configs.size(); i++) {
            int id = configs.get(i).getId();
            String type = configs.get(i).getType();
            try {
                NotifyMode mode = (NotifyMode) Class.forName(type).newInstance();
                modeMap.put("" + id, mode);
            } catch (Exception e) {
                logger.error("failed to get alarm node instance", e);
            }
        }
    }

    public static NotifyModeFactory getInstance() {
        if (instance == null) {
            instance = new NotifyModeFactory();
        }
        return instance;
    }

    public NotifyMode getNotifyMode(int alarmMode) {
        return modeMap.get("" + alarmMode);
    }

}
